<template>
  <div class="rightBodyContent">
    <div class="rightBodyContent-in">
      <div class="tab-body mb-10">
        <div class="tab-box">
          <!--          // 0待审核1通过2驳回3借出4归还 -->
          <!--          0待审核1通过2驳回3完成 -->
          <el-radio-group v-model="radioStatus" size="small" @change="changeFn()">
            <el-radio-button label="all">全部</el-radio-button>
            <el-radio-button :label="0">待审核</el-radio-button>
            <el-radio-button :label="1">待借出</el-radio-button>
            <el-radio-button :label="2">待归还</el-radio-button>
            <el-radio-button :label="3">已归还</el-radio-button>
            <el-radio-button :label="4">已驳回</el-radio-button>
          </el-radio-group>
        </div>
      </div>
      <div class="search-list mb-10">
        <el-input v-model="editForm.name" auto-complete="off" placeholder="填写卷目名" size="small"
                  class="w-140 mr-10"></el-input>
        <el-input v-model="editForm.sn" auto-complete="off" placeholder="填写卷目号" size="small" class="w-140"></el-input>
        <el-button size="small" type="primary" plain class=" ml-10" @click="search('search')">搜索</el-button>
        <el-button size="small" plain @click="search('resct')">重置</el-button>
        <downexcel type="badgeFiles" :option="{status:radioStatus !== 'all'?radioStatus:'',style: 2,name:editForm.name,sn: editForm.sn}"></downexcel>
      </div>
      <!--本体列表，数据 -->
      <div class="table-body">
        <div class="table-body-box">
          <el-table
              ref="multipleTable"
              :data="arryList"
              :stripe="tableStyle.tableStripe"
              :border="tableStyle.tableBorder"
              tooltip-effect="dark"
              header-cell-class-name="table-text-c"
              style="width: 100%">
            <el-table-column
                prop="name"
                label="卷目名"
                align="center">
            </el-table-column>
            <el-table-column
                label="卷目号"
                align="center"
                prop="sn">
            </el-table-column>
            <el-table-column
                prop="content"
                label="用途"
                align="center">
            </el-table-column>
            <el-table-column
                prop="create_time"
                label="创建时间"
                align="center">
            </el-table-column>
            <el-table-column
                prop="examine_time"
                label="审核信息"
                align="center">
              <template slot-scope="scope">
                <p>{{scope.row.examineuser?scope.row.examineuser.realname:''}}</p>
                <p>{{scope.row.examine_time}}</p>
              </template>
            </el-table-column>
            <el-table-column
                prop="lend_time"
                label="借出时间"
                align="center">
            </el-table-column>
            <el-table-column
                prop="return_time"
                label="归还时间"
                align="center">
            </el-table-column>
            <el-table-column
                prop="status"
                label="状态"
                align="center">
              <template slot-scope="scope">
                <!--                0待审核1待借出2待归还3已归还4驳回-->
                <span v-if="scope.row.status==0">待审核</span>
                <span v-if="scope.row.status==1">待借出</span>
                <span v-if="scope.row.status==2">待归还</span>
                <span v-if="scope.row.status==3">已归还</span>
                <span v-if="scope.row.status==4" class="examinBtn">已驳回 <i @click="shoeExaminFn(scope.$index)">查看驳回说明</i></span>
              </template>
            </el-table-column>
            <el-table-column
                label="操作"
                align="center"
                width="150"
                :ksy="10"
                v-if="radioStatus==1 ||radioStatus==2 ||radioStatus==0 || radioStatus=='all'">
              <template slot-scope="scope">
                <!--                0待审核1待借出2待归还3已归还4驳回-->
                <el-button type="primary" size="small" v-if="scope.row.status==0" @click="examinBtn(1,scope.row.id)">
                  通过
                </el-button>
                <el-button size="small" @click="examinBtn(2,scope.row.id)" class="ml-10" v-if="scope.row.status==0">驳回
                </el-button>
                <el-button size="small" v-if="scope.row.status==1" @click="lendFn(1,scope.row)">借出确认
                </el-button>
                <el-button size="small" v-if="scope.row.status==2" @click="lendFn(2,scope.row)">归还确认</el-button>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </div>
      <!--工具条 分页-->
      <el-col :span="24" class="toolbar">
        <el-pagination
            background
            layout="total, prev, pager, next"
            :total="page.total"
            :page-size="page.pagesize"
            @current-change="handleSizeChange">
        </el-pagination>
      </el-col>
    </div>
  </div>
</template>

<script>
import {pagination, tableoption} from '@/utils/util.js'
import {files_index, files_lend, files_returns, files_examine} from '@/api/admin/badge'

export default {
  components: {},
  data() {
    return {
      arryList: [], // 页面数据列表
      // 设置table样式
      tableStyle: tableoption,
      // 设置table页面分页所需
      page: {
        pageindex: pagination.pageIndex,
        pagesize: pagination.pageSize,
        total: pagination.total
      },
      editForm: {
        name: '',
        sn: '',
        style: 2
      },
      radioStatus: 'all'
    }
  },
  created() {
    this.InitFn()
  },
  watch: {
    radioStatus() {
      this.search('resct')
    }
  },
  methods: {
    // 初始化
    InitFn() {
      // style 1 我的申请 2 我的审核
      let option_ = JSON.parse(JSON.stringify(this.editForm))
      option_.p = this.page.pageindex
      if (this.radioStatus !== 'all') {
        option_.status = this.radioStatus
      }
      files_index(option_).then(res => {
        console.log('res:', res)
        this.arryList = JSON.parse(JSON.stringify(res.list.data))
        this.page.total = res.list.total
      })
    },
    examinBtn(type, id) {
      let that = this;
      if (type === 1) {
        this.$confirm('确认档案的审核, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          that.subimitExamin(type, id)
        }).catch(() => {

        });
      } else {
        this.$prompt('输入驳回说明', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
        }).then(({value}) => {
          // value
          that.subimitExamin(type, id, value)
        }).catch(() => {

        });
      }
    },
    search(option) {
      this.page.pageindex = 1;
      if (option === 'resct') {
        this.editForm.name = ''
        this.editForm.sn = ''
      }
      this.InitFn()
    },
    changeFn() {
      this.InitFn()
    },
    // 分页
    handleSizeChange(val) {
      this.page.pageindex = val
      this.InitFn()
    },
    shoeExaminFn(index) {
      this.$confirm(this.arryList[index].content, '驳回说明', {
        showCancelButton: false,
        confirmButtonText: '确认',
        type: 'warning'
      }).then(() => {
        // :visible.sync="detailVisible" @InitFn="InitFn" :sealId="sealId"
        // this.sealId = this.arryList[index].id;
        // this.detailVisible = true;
      }).catch(() => {
      })
    },
    subimitExamin(type, id, value) {
      let n = this;
      let option = {id: id, type: type}
      if (type === 2) {
        option.content = value;
      }
      files_examine(option).then(res => {
        console.log('res===>', res)
        if (!res.code) {
          n.InitFn()
        } else {
          this.$message.error(res.msg)
        }
      })
    },
    lendFn(type, row) {
      let that = this
      let title_ = '确认借出当前档案，是否继续?'
      if (type === 2) {
        title_ = '确认归还当前档案，是否继续?'
      }
      this.$confirm(title_, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        that.submitLend(type, row.id)
      }).catch(() => {

      });
    },
    submitLend(type, id) {
      let n = this
      if (type === 1) {
        files_lend({id: id}).then(res => {
          if (!res.code) {
            n.InitFn()
          } else {
            this.$message.error(res.msg)
          }
        })
      } else {
        files_returns({id: id}).then(res => {
          if (!res.code) {
            n.InitFn()
          } else {
            this.$message.error(res.msg)
          }
        })
      }
    }
  },
  mounted() {
  },
  // 缓存机制 end
}
</script>

<style scoped>

.wx-user-box-line img {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  margin-right: 5px;
}

.wx-user-box-line {
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-wx {
  cursor: pointer;
  padding: 5px;
}

.btn-wx:hover {
  color: #1b8de5;
  text-decoration: underline;
}

.delet-wx {
  color: red;
  cursor: pointer;
}

.delet-wx:hover {
  text-decoration: underline;
}

.tab-body {
  display: flex;
  align-items: center;
}

.tab-box {
  flex: 1;
}

.tab-box-list {
  display: flex;
  align-items: center;
}

.examinBtn {
  display: flex;
  flex-direction: column;
  align-items: center;
  color: red;
}

.examinBtn i {
  font-style: normal;
  color: #1b8de5;
  cursor: pointer;
  font-size: 12px;
}

</style>
